<style lang="scss" scoped>
.list {
  padding: 10px;
  div {
    margin: 5px;
  }
  dl {
    display: flex;
    padding: 10px;
    dt {
      width: 50px;
      img {
        width: 50px;
        height: 50px;
      }
      margin: 0 10px;
    }
    dd {
      .name {
        font-size: 20px;
        font-weight: 800;
      }
    }
  }
}
.YY {
  width: 100%;
  line-height: 50px;
  div {
    width: 100%;
    height: 50px;
    text-align: center;
    font-size: 20px;
  }
}
.tabs {
 
  flex-wrap: wrap;
  background-color: #fff;
  font-size: 14px;
}

.tab {
  margin: 5px;
  padding: 5px;
  margin-left: 10px;
  width: 100%;
  font-size: 18px;
  border-radius: 50px;
  text-align: center;
}

.box {
  width: 100vw;
  height: 100%;
  display: flex;
  .left {
    flex: 8;
    height: 100%;
    overflow: auto;
    div {
      width: 100%;
    }
  }
  .right {
    height: 100%;
    overflow: auto;
    flex: 7;
    div {
      display: flex;
      padding-left: 20px;
      width: 100%;
      height: 46px;
      align-items: center;
    }
  }
}
.activeIndex {
  background: #ccc;
}
</style>
<template>
  <van-dropdown-menu ref="menuRef" >
    <van-dropdown-item :title="text" v-model="value" ref="itemRef">
      <div class="box">
      <!-- 左侧城市 -->
      <div class="left">
        <van-sidebar v-model="active">
          <van-sidebar-item
            v-for="(item, index) in areaList.province_list"
            :key="index"
            :title="item"
            @click="getCity(index)"
          >
          </van-sidebar-item>
        </van-sidebar>
      </div>
      <!-- 右侧市区 -->
      <div class="right">
        <div
          v-for="(v, i) in arr1"
          :key="i"
          :class="{ activeIndex: currentIndexcity == i }"
        >
          <div @click="handCity(v, i)">{{ v }}</div>
        </div>
      </div>
    </div>
    </van-dropdown-item>
<!-- 医院等级 -->
    <van-dropdown-item
      :title="text1"
      ref="itemRef1"
      class="menu2"
      v-model="value1"
    >
      <div class="tabs">
        <div
          v-for="(tab, index) in listTap1"
          :key="index"
          class="tab"
          :class="{ active: currentIndex === index }"
          @click="tabClick1(tab, index)"
        >
          {{ tab }}
        </div>
      </div>

      
    </van-dropdown-item>
  </van-dropdown-menu>

  <van-list
    v-model:loading="loading"
    :finished="finished"
    finished-text="没有更多了"
    @load="onLoad"
    ><div class="list" v-for="(v, i) in SearchSocoData" :key="i" :v="v">
      <dl>
        <dt>
          <img :src="v.socoimage" alt="" />
        </dt>
        <dd>
          <div class="name">{{ v.nosocomium }}</div>
          <div>
            <van-tag plain type="primary">{{ v.socolv }}</van-tag>
            {{ v.socoadmin }}
          </div>
        </dd>
      </dl>
    </div></van-list
  >
</template>
<script setup lang="ts">
import { onMounted, ref,reactive } from 'vue'
import axios from 'axios'
import type { bookStata, doctorState, socoState,ListState } from '@/interface'
import { useRoute, useRouter } from 'vue-router'
import { areaList } from '@vant/area-data'
const route = useRoute()
const router = useRouter()
const loading = ref(true)
const finished = ref(true)
const onLoad = () => {}
const SearchBookData = ref<bookStata[]>([])
const SearchDoctorData = ref<doctorState[]>([])
const SearchSocoData = ref<socoState[]>([])
onMounted(() => {
  route.query.searchValue
  console.log(route.query.searchValue)
  axios
    .get('/api/search', {
      params: {
        pageCode: 1,
        pageSize: 10,
        searchValue: route.query.searchValue,
      },
    })
    .then(res => {
      const { data } = res.data
      console.log(data)

      SearchBookData.value = data.book
      SearchDoctorData.value = data.doctor
      SearchSocoData.value = data.soco
    })
})
const Doctordetail = (v: doctorState) => {
  router.push('/doctordetail?id=' + v.doctorid)
}
// 城市
const showcity = ref(false)
const showPopupcity = () => {
  showcity.value = true
}
const paramsData = reactive({
  pageCode: 1,
  pageSize: 10,
  lv: '',
  city: '',
  state: '',
  admin: '',
  search: '',
})

const currentIndexcity = ref(0)
const city = ref('北京')
const arr1 = ref<string[]>(['北京市'])

const getCity = (v: string) => {
  arr1.value = []

  for (let key in areaList.city_list) {
    if (v.slice(0, 2) == key.slice(0, 2)) {
      arr1.value.push(areaList.city_list[key])
      console.log(v)
    }
  }
}

const itemRef=ref()
const itemRef1=ref()
const handCity = (v: string, i: number) => {
  currentIndex.value = i
  showcity.value = false
  city.value = v
  paramsData.city = v
  text.value = v
  if (v == '不限') {
    v = ''
  }
  paramsData.city = v
  console.log(paramsData)
  axios.get('/api/nosocomium/list', { params: paramsData }).then(res => {
    console.log(res)
    doctorState.value = res.data.data
    listData.value = res.data.data
  })
  itemRef.value.toggle()
}

const show = ref(false)
const active = ref(0)
const value = ref(0)
const value1 = ref(0)
const currentIndex = ref(0)
const listData = ref<ListState[]>([])

const doctorState = ref([])
const text = ref('全国')
const listTap = ref(['全部', '公立', '私立'])

const socoList = ref([])
const text1 = ref('医院等级')
const listTap1 = ref([
  '不限',
  '三级甲等',
  '三级乙等',
  '三级丙等',
  '二级甲等',
  '二级乙等',
  '二级丙等',
  '一级甲等',
  '一级乙等',
  '一级丙等',
])

const getList = () => {
  axios
    .get('/api/nosocomium/list', {
      params: paramsData,
    })
    .then(res => {
      const { data } = res.data
      console.log(data)
      listData.value = data
    })
}
getList()


// 等级筛选
const tabClick1 = (tab: string, index: number) => {
  currentIndex.value = index
  text1.value = tab
  if (tab == '不限') {
    tab = ''
  }
  paramsData.lv = tab
  axios.get('/api/nosocomium/list', { params: paramsData }).then(res => {
    console.log(res)
    socoList.value = res.data.data
    listData.value = res.data.data
  })
  itemRef1.value.toggle()
  getList()
}


</script>
